package com.hc.weatherhc.controller;

import com.hc.weatherhc.domain.City;
import com.hc.weatherhc.service.CityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@RestController
public class WeatherController {
    @Autowired
    RestTemplate restTemplate;
    @Autowired
    CityService cityService;

    @RequestMapping(value = "/weather")
    public String weather(String city){


        String result=restTemplate.getForObject("https://apis.tianapi.com/tianqi/index?key=2af8ed08605c20f76f8183d1b702474b&city="+city+"&type=7",String.class);

        List<City> cityList=cityService.cityList();

        for(City c:cityList){
            System.out.println("city:"+c.getCityId()+","+c.getCity());
        }

        return result;



    }
}
